<template>
  <el-dialog v-model="dialogVisible" title="导入问题清单" width="1000" :before-close="handleClose">
    <el-table :data="tableData" :max-height="tableMaxHeight">
      <el-table-column label="报名时间" width="160" prop="_add_time_str" />
      <el-table-column prop="curriculum_name" label="课程名称" width="450" />
      <el-table-column label="报名所属" width="130">
        <template #default="scope">
          {{scope.row.affiliation||'-'}}
        </template>
      </el-table-column>
      <el-table-column prop="name" label="姓名" width="100" />
      <el-table-column prop="mobile" label="联系方式" width="120" />
      <el-table-column prop="identityCard" label="身份证号" width="170" />
      <el-table-column prop="graduationMajor" label="毕业专业" width="180" />
      <el-table-column prop="workYears" label="累计工作年限" width="120" />
      <el-table-column prop="price" label="课程价格" />
      <el-table-column prop="errText" label="错误原因" fixed="right" width="200" />
    </el-table>
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="handleClose">取消</el-button>
        <el-button type="primary" @click="save" :loading="loading">
          导出
        </el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script setup lang="ts">
import useCounterStore from "@/store/counter";
const counter = useCounterStore();
const instance = getCurrentInstance();
const { proxy } = getCurrentInstance();

let dialogVisible = ref(false);
let tableData = ref([]);
let loading = ref(false);

let tableMaxHeight = computed(() => {
  return `${window.innerHeight * 0.7}px`;
});

function open(list) {
  tableData.value = list;
  dialogVisible.value = true;
}

function handleClose() {
  tableData.value = [];
  dialogVisible.value = false;
}

async function save() {
  try {
    loading.value = true;
    let list = [];
    tableData.value.forEach((element) => {
      list.push({
        报名时间: proxy.$utils.dateTimeFormateFn(element._add_time, "all"),
        课程名称: element.curriculum_name,
        报名所属: element.affiliation || "-",
        姓名: element.name,
        联系方式: element.mobile,
        身份证号: element.identityCard,
        毕业专业: element.graduationMajor,
        累计工作年限: element.workYears,
        课程价格: element.price,
        错误原因: element.errText,
      });
    });
    let cols = [{ wch: 15 }, { wch: 45 }]; //设置表头样式
    let query = {
      jsonData: list,
      cols,
    };
    await proxy.$utils.exportToExcel(query, "导入失败数据");
    handleClose();
  } catch (error) {
    console.log("导出失败", error);
  } finally {
    loading.value = false;
  }
}

defineExpose({ open });
</script>



<style lang="scss" scoped>
.container {
}
</style>



